import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //解决浏览器中的乱码
        resp.setContentType("text/html; charset = utf8");
        //这个是打印在 tomcat 的控制台上
        System.out.println("你好 java");
        //把内容显示到页面上, 把 "hello word" 这个字符串作为 http 响应的 body 部分
        //这个部分就会被浏览器显示到页面上
        resp.getWriter().write("你好 java");
    }
}
